<include file="Public/siteTopbar" />
<link rel="stylesheet" href="__STATIC__/css/user.css" type="text/css">
<include file="Public/header" />


<div class="container logintop">
<h3>My Account</h3>
<p>My Account allows you to manage your setting and preferences. Existing wish list or project portfolio logins can be used to login to My Account.</p>
</div>


<div class="container usercenter">
    <div class="col-sm-6">
        <div class="longinBox">
            <h3>- LOG IN TO ACCOUNT -</h3>
             <form action="{:U('Home/User/do_login')}" method="post">
            <input type="hidden" name="referurl" id="referurl" value="{$referurl}">
            <ul class="form-list">
            <li>
            <label for="email" class="required"><em>*</em>Email Address</label>
            <input type="text" id="username" name="username"  onKeyDown="if(event.keyCode==13){checkSubmit();}" value="" class="loginInput required-entry validate-email" title="Email Address">
            </li>
            <li>
            <label for="pass" class="required"><em>*</em>Password</label>
            <input type="password" name="password" id="password"  onKeyDown="if(event.keyCode==13){checkSubmit();}"  class="loginInput required-entry validate-password" id="pass" title="Password">
            </li>


            <li><a  href="{:U('User/forget_pwd')}"   class="f-left">Forgot Your Password?</a></li>
            <li><button type="button" class="loginbutton"  onClick="checkSubmit()" title="Login" name="send" id="send2"><span><span>Login</span></span></button></li>
            </ul>
                        </form>
        </div>
    </div>
    <div class="col-sm-6">
        <div class="longinBox" style="min-height:416px;">
            <h3>- CREATE AN ACCOUNT -</h3>
            <p>By creating an account with our store, you will be able to move through the checkout process faster, store multiple shipping addresses, view and track your orders in your account and more.</p>
             <button type="button" title="Create an Account" class="loginbutton" onclick="window.location='{:U('Home/User/reg')}';"><span><span>Create an Account</span></span></button>
        </div>
    </div>
</div>


<include file="Public/footer" />

<script>

	function checkSubmit()
	{
		var username = $.trim($('#username').val());
		var password = $.trim($('#password').val());
		var referurl = $('#referurl').val();
		//var verify_code = $.trim($('#verify_code').val());
		if(username == ''){
	
			 		layer.msg('Email Address is a required field.', {
                            icon: 1,  
                            time: 2000 
                        });
						return false;
		}
		
		if(!checkEmail(username)){

			 		layer.msg('Email Address is format does not match.', {
                            icon: 1,  
                            time: 2000 
                        });
			return false;
		}
		if(password == ''){
			
			 		layer.msg('Password is a required field.', {
                            icon: 1,  
                            time: 2000 
                        });
						return false;
		}
		/*if(verify_code == ''){
			alert('驗證碼不能為空');
			return false;
		}*/

		$.ajax({
			type : 'post',
			url : '/index.php?m=Home&c=User&a=do_login&t='+Math.random(),
			data : {username:username,password:password,referurl:referurl},
			dataType : 'json',
			success : function(res){
				if(res.status == 1){
					window.location.href = res.url;
				}else{
					layer.msg(res.msg, {
                            icon: 1,  
                            time: 2000 
                        });
				}
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				//showErrorMsg('網絡失敗，請刷新頁面後重試');

					layer.msg('Network failed, please refresh the page and try again', {
                            icon: 1,  
                            time: 2000 
                        });
			}
		})

	}


    function checkEmail(str){
        var reg = /^[a-z0-9]([a-z0-9\\.]*[-_]{0,4}?[a-z0-9-_\\.]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+([\.][\w_-]+){1,5}$/i;
        if(reg.test(str)){
            return true;
        }else{
            return false;
        }
    }

</script>
</div>
</body>
</html>